package com.efast.dmom.aps.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.aps.bean.Plan;
import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.PlanService;

/**
 * 
 * @author Wj
 * @date 2020年2月18日
 *
 */
@Controller
@RequestMapping("/plan")
public class PlanController {

	@Autowired
	private PlanService planService;

	// To achieve the plan to add, delete, update and query
	@RequestMapping(value = "/basicOperateByPlan")
	public @ResponseBody ResultBean basicOperateByPlan(@RequestBody Plan plan) {
		// Determine the new
		if (plan.getInnerEntity().getModificationFlag() == IModificationFlags.NEW) {
			return planService.save(plan);
		// Judge update
		} else if (plan.getInnerEntity().getModificationFlag() == IModificationFlags.MODIFIED) {
			return planService.update(plan);
		// Judge to delete
		} else if (plan.getInnerEntity().getModificationFlag() == IModificationFlags.DELETED) {
			return planService.delete(plan);
		}
		ResultBean resultBean = new ResultBean(true,' ');
		resultBean.setSuccess(false);
		resultBean.setMessage("计划订单不存在!");
		return resultBean;	
	}
	
	//To achieve the plan to decomposition
	@RequestMapping(value = "/decompositionByPlan")
	public @ResponseBody ResultBean decompositionByPlan(@RequestBody Plan plan) {
		ResultBean resultBean = new ResultBean(true,' ');
		planService.decompositionByPlan(plan);
		resultBean.setSuccess(true);
		resultBean.setMessage("订单分解成功!");
		return resultBean;
	}
	
	
	@RequestMapping(value = "/getById")
	public @ResponseBody Plan getById(@RequestBody long planId) {
		return planService.getById(planId);
	}
	
	
	@RequestMapping(value = "/getByPlanNo")
	public @ResponseBody Plan getByPlanNo(@RequestBody String planNo) {
		return planService.getByPlanNo(planNo);
	}
	@RequestMapping(value = "/getByStatus")
	public @ResponseBody List<Plan> getByStatus(@RequestBody String status) {
		return planService.getByStatus(status);
	}
	
}
